package com.leejw.tradeblogsystem.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leejw.tradeblogsystem.common.ExcelUtil;
import com.leejw.tradeblogsystem.common.Result;
import com.leejw.tradeblogsystem.mapper.RecordMapper;
import com.leejw.tradeblogsystem.model.Record;
import com.leejw.tradeblogsystem.model.Shares;
import com.leejw.tradeblogsystem.service.RecordService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author: jwli3
 * @Desc:
 * @create: 2024-08-27
 **/
@Service
public class RecordServiceImpl extends ServiceImpl<RecordMapper, Record> implements RecordService {

    @Autowired
    private RecordMapper recordMapper;
    @Override
    public Result saveRecord(Record recordVO) {
        Record tempRecord = new Record();
        BeanUtils.copyProperties(tempRecord,recordVO);
        save(tempRecord);
        return Result.success(tempRecord);
    }

    @Override
    public List<Record> getAllRecords() {
        return recordMapper.getAllRecords();
    }

    @Override
    public Integer importRecordExcel(MultipartFile excelFile, Record record) throws Exception {
        List<Record>list = ExcelUtil.importExcel(excelFile,record);
        return recordMapper.importBatchRecords(list);
    }


}
